package service

import (
	"duoke/model"
	"duoke/tables"
	"errors"
	"github.com/gin-gonic/gin"
)

var Request = new(requestService)

type requestService struct{}

// 用户基础信息
type UserStruct struct {
	Id   int `json:"id"`
	Acid int `json:"acid"`
}

// 员工基础信息
type StaffStruct struct {
	Id      int `json:"id"`
	Acid    int `json:"acid"`
	GoodsId int `json:"goodsId"`
}

// 当前账户
type AccountStruct struct {
	Id       int    `json:"id"`
	Role     string `json:"role"`
	GoodsIds string `json:"goods_ids"`
	Pid      int    `json:"pid"`
}
type SeparateAccountsStruct struct {
	Id       int    `json:"id"`
	SubMchId string `json:"sub_mch_id"`
}

func (s *requestService) User(c *gin.Context) (UserStruct, error) {
	userVal, isExists := c.Get("user")
	if !isExists {
		return UserStruct{}, errors.New("request用户信息不存在")
	}
	user := userVal.(UserStruct)
	return user, nil
}

func (s *requestService) Goods(c *gin.Context) (model.ReqGoods, error) {
	goodsVal, isExists := c.Get("goods")
	if !isExists {
		return model.ReqGoods{}, errors.New("request商品信息不存在")
	}
	goods := goodsVal.(model.ReqGoods)
	return goods, nil
}
func (s *requestService) GoodsUser(c *gin.Context) (tables.GoodsUser, error) {
	goodsUserVal, isExists := c.Get("goodsUser")
	if !isExists {
		return tables.GoodsUser{}, errors.New("request商品用户信息不存在")
	}
	goodsUser := goodsUserVal.(tables.GoodsUser)
	return goodsUser, nil
}

func (s *requestService) Staff(c *gin.Context) (StaffStruct, error) {
	staffVal, isExists := c.Get("staff")
	if !isExists {
		return StaffStruct{}, errors.New("request员工信息不存在")
	}
	staff := staffVal.(StaffStruct)
	return staff, nil
}

func (s *requestService) Account(c *gin.Context) (AccountStruct, error) {
	accountVal, isExists := c.Get("account")
	if !isExists {
		return AccountStruct{}, errors.New("request账户信息不存在")
	}
	account := accountVal.(AccountStruct)
	return account, nil
}
func (s *requestService) SeparateAccounts(c *gin.Context) (SeparateAccountsStruct, error) {
	accountVal, isExists := c.Get("separate_accounts")
	if !isExists {
		return SeparateAccountsStruct{}, errors.New("request账户信息不存在")
	}
	account := accountVal.(SeparateAccountsStruct)
	return account, nil
}
